package com.simple.cms.biz.impl;


import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.simple.cms.biz.IProductService;
import com.simple.cms.model.mapper.ProductConverter;
import com.simple.cms.model.request.ProductForm;
import com.simple.cms.model.response.ProductBaseInfo;
import com.simple.cms.repository.entity.Product;
import com.simple.cms.repository.mapper.ProductMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 产品表 服务实现类
 * </p>
 *
 * @author kin
 * @since 2017-07-17
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Override
    public void addProduct(ProductForm productForm) {
        Product product = ProductConverter.converterToDo(productForm);
        baseMapper.insert(product);
    }

    @Override
    public Page<ProductBaseInfo> getProductList(Page<ProductBaseInfo> page) {
        List<Product> productInfoList = baseMapper.selectPage(page, null);
        page.setRecords(ProductConverter.converterToInfoList(productInfoList));
        return page;
    }
}
